import {setStorageSync, getStorageSync} from "../utils/Storage";

let User = {
    /*
    * 登录
    * */
    login: function () {
        return new Promise(function (resolve, reject) {
            setTimeout(function () {
                const APP = getApp();
                setStorageSync("userInfo", "测试");
                if (APP) {
                    APP.globalData.userInfo = "测试";
                    APP.getUserInfoCallback && typeof APP.getUserInfoCallback === "function" ? APP.getUserInfoCallback("测试"): null;
                }
                resolve("陈锐");
            }, 3000)
        })
    },

    /*
    * 确认完成
    * */
    loginComplete: function () {
        return new Promise(function (resolve) {
            const APP = getApp();
            let userInfo = APP.globalData.userInfo || getStorageSync("userInfo");
            if (userInfo) {
                User.loginComplete = function () {return userInfo}
                resolve(userInfo);
            } else {
                APP.getUserInfoCallback = function (res) {
                    User.loginComplete = function () {return userInfo}
                    resolve(res);
                }
            }
        })
    },
}

/*
* 登录完成
* */

module.exports = User